/**
 * 2
 *  
 * @Author : roryrywang
 * @DateTime : 24-9-3 下午6:56
 */

#include <iostream>

using namespace std;

int main() {
    int n;
    string s;
    char ch;
    cin >> n >> s >> ch;
    if (ch == 'g') {
        cout << 0;
        return 0;
    }
    int res = 0;
    int p = 0;
    while (p < 2 * n) {
        while (p < 2 * n && s[p] != ch) {
            p++;
        }
        int tmp = p;
        while (p < 2 * n && s[p] != 'g') {
            p++;
        }
        if (p < 2 * n) {
            res = max(res, p - tmp);
        }
    }
    cout << res << endl;
    return 0;
}